<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
	.item{
		width: 95px;
		display: inline-block;
		margin-left: 5px;
	}
</style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
        	<td style="width:45%;">
        		<span class="item">产品名称：</span>
        		<div id="s_pro_name" emptyText="请选择..." class="mini-combobox" style="width:220px;"  popupWidth="165" textField="name" valueField="id" 
				    url="medical_medicine_view.do" multiSelect="true"  showClose="true" oncloseclick="onCloseClick" >     
				    <div property="columns">
				        <div header="产品名称" field="name"></div>
				    </div>
				</div>
            </td>
            <td style="width:45%;">
            	<span class="item">媒体名称：</span>
                <div id="s_media_name" emptyText="请选择..." class="mini-combobox" style="width:220px;"  popupWidth="165" textField="name" valueField="id" 
				    url="medical_media_view_all.do" multiSelect="true"  showClose="true" oncloseclick="onCloseClick" >     
				    <div property="columns">
				        <div header="媒体名称" field="name"></div>
				    </div>
				</div>
            </td>
            <td style="display: inline-block;">&nbsp;</td>
        </tr>
        <tr>
        	<td>
            	<span class="item">投放开始日期：</span>
                <input name="placeStartTime" emptyText="请选择..."  class="mini-datepicker" style="width: 160px" allowInput="false"/>
            </td>
        	<td>
                <span class="item">投放截止日期：</span>
                <input name="placeEndTime" emptyText="请选择..." class="mini-datepicker" style="width: 160px" allowInput="false"/>
            </td>
            <td style="white-space:nowrap;">
               	<a class="mini-button" iconCls="icon-search"  onclick="search()">查询</a>
           	</td>
        </tr>
    </table>           
</div>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:auto;">
	        <tr>
	            <td>
	            <sec:authorize url='/medical_media_place_add.do'>
					<a class="mini-button" iconCls="icon-add" onclick="onAddMedia('添加媒体投放信息')">增加媒体投放</a>
				</sec:authorize>
				<sec:authorize url='/medical_media_place_edit.do'>
					<a class="mini-button" iconCls="icon-edit" onclick="onEditMedia('编辑媒体投放信息')">编辑媒体投放</a>
				</sec:authorize>
				<sec:authorize url='/medical_media_place_delete.do'>
					<a class="mini-button" iconCls="icon-remove" onclick="onRemoveMedia()">批量删除</a>
				</sec:authorize>
				<sec:authorize url='/export_current_media_place_data.do'>
					<a class="mini-button" iconCls="icon-download" onclick="exportCurrentData()">导出当前</a>
					<a class="mini-button" iconCls="icon-download" onclick="exportAllData()">导出所有</a>
				</sec:authorize>
	            </td>
	        </tr>
	    </table>           
	</div>
	<div class="mini-fit" >
    <div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20"
		url="media_place_views.do" style="width:100%;height:100%;" allowCellSelect="true" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div type="checkcolumn"></div>
			<div width="70" headerAlign="center" renderer="onActionRenderer" align="center">相关操作</div>
			<div field="medicineName" width="100" headerAlign="center" align="center">产品名称</div>
			<div field="mediaName" width="100" headerAlign="center" align="center">媒体名称</div>
			<div field="publishNumbers" width="100" headerAlign="center" align="center">刊登号码</div>
			<div field="costs" width="60" headerAlign="center" align="center">广告费用(元)</div>
			<div field="placeStartTime" width="90" dateFormat="yyyy-MM-dd" headerAlign="center" align="center">投放开始日期</div>
			<div field="placeEndTime" width="90" dateFormat="yyyy-MM-dd" headerAlign="center" align="center">投放截止日期</div>
			<div field="startTime" width="80" headerAlign="center" allowSort="true"  align="center">开始时间</div>
			<div field="endTime" width="80" headerAlign="center" allowSort="true" align="center">结束时间</div>
			<div field="play" width="50" headerAlign="center" align="center">播放中</div>
		</div>
	</div>
	</div>

<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.load();
	
	//查询
	function search() {
	    var medicineId = mini.get("s_pro_name").getValue();
	    var mediaId = mini.get("s_media_name").getValue();
	    var placeStartTime = mini.getbyName("placeStartTime").getFormValue();
	    var placeEndTime = mini.getbyName("placeEndTime").getFormValue();
	    grid.load({ medicineId: medicineId,
	    	mediaId: mediaId,
	    	placeStartTime: placeStartTime,
	    	placeEndTime: placeEndTime
	    });
	}
	
	function onAddMedia(title) {
	    mini.open({
	   		url: "medical_media_place_add.do",
	   		allowResize:false,
           	title: title, width: 450, height: 460,
           	onload: function () {
               var iframe = this.getIFrameEl();
               var data = { action:"new" };
               iframe.contentWindow.SetData(data);
       		},
    	   	ondestroy: function (action) {
    	   		if(action == 'succ'){
    	   			mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
    	   			grid.load();
    	   		}
            }
     	});
	}
		
	function onEditMedia(title) {
		var row = grid.getSelecteds();
		if(row.length == 1){
    		mini.open({
    	   		url: "medical_media_place_edit.do",
    	   		allowResize:false,
               	title: title, width: 450, height: 460,
               	onload: function () {
                   var iframe = this.getIFrameEl();
                   var data = { row: row[0] };
                   iframe.contentWindow.SetData(data);
          		},
	    	   	ondestroy: function (action) {
	    	   		if(action == 'succ'){
	    	   			mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "修改成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
		    	   		grid.load();
	    	   		}
                }
         	});
	    }else{
	    	mini.alert("请选择一条记录");
	    }
	}
	
	function onRemoveMedia(e) {
		var rows = grid.getSelecteds();
	    if (rows.length > 0) {
	    	var mIds = '';
   			mini.confirm("确定删除记录？", "确定？",
        	function (action) {
           		if (action == "ok") {
           			var ids = [];
           			for(var i=0;l=rows.length,i<l;i++){
           				var r = rows[i];
           				ids.push(r.id);
           			}
           			mIds = ids.join(",");
  					$.post('medical_media_place_delete.do', {id: mIds}, function(data){
  	    				if(data.success){
   	    					mini.showMessageBox({
			                    title: "提示",
			                    showModal:false,
			                    iconCls: "mini-messagebox-info",
			                    message: "删除成功！",
			                    timeout: 3000,
			                    x: 'right',
			                    y: 'bottom',
			                });
  	    					grid.load();
  	    				}else{
  	    					mini.alert("id不能为空，删除失败！");
  	    				}
 	    			}, "json");
   				}
   			});
	    }else{
	    	mini.alert("请选择一条记录");
	    }
	}

	//查看
	function onActionRenderer(e) {
		var s = '<a class="New_Button" href="javascript:view()">'+'查看详细'+'</a> ';
	    return s;
	}
	
	function view(){
		var row = grid.getSelected();
		if(row){
    		mini.open({
    	   		url: "medical_media_place_view.do",
    	   		allowResize:false,
               	title: "媒体信息", width: 450, height: 460,
               	onload: function () {
                   var iframe = this.getIFrameEl();
                   var data = { row: row };
                   iframe.contentWindow.SetData(data);
          		}
         	});
	    }else{
	    	mini.alert("请选择一条记录");
	    }
	}
	
	//导出全部
	function exportAllData(){
		location.href="export_all_media_place_data.do"; 
	}
	//导出当前页数据
	function exportCurrentData() {
		var data =grid.getData();
		var ids = [];
		$.each(data , function(){
	        ids.push(this.id);
	    });
		var id = ids.join(',');
		location.href="export_current_media_place_data.do?ids=" +id;
	}
	
	function onCloseClick(e) {
        var obj = e.sender;
        obj.setText("");
        obj.setValue("");
    }
	
</script>
</body>
</html>